package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ajax")
public class Demo01AjaxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("调用dopost请求 ");
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("如果没有dopost 就是直接调用doget请求");
       //写业务  如果post业务跟get一样
        System.out.println("我们这里接收前端的请求，并完成处理");
        //假设请求中有参数
        String username = request.getParameter("username");

        System.out.println("前端传递过来的用户名是:"+username);


        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("该"+username+"太受欢迎了！");
    }
}
